<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - dnn_semantic_segmentation_ex.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
</font><font color='#009900'>/*
    Semantic segmentation using the PASCAL VOC2012 dataset.

    In segmentation, the task is to assign each pixel of an input image
    a label - for example, 'dog'.  Then, the idea is that neighboring
    pixels having the same label can be connected together to form a
    larger region, representing a complete (or partially occluded) dog.
    So technically, segmentation can be viewed as classification of
    individual pixels (using the relevant context in the input images),
    however the goal usually is to identify meaningful regions that
    represent complete entities of interest (such as dogs).

    Instructions how to run the example:
    1. Download the PASCAL VOC2012 data, and untar it somewhere.
       http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
    2. Build the dnn_semantic_segmentation_train_ex example program.
    3. Run:
       ./dnn_semantic_segmentation_train_ex /path/to/VOC2012
    4. Wait while the network is being trained.
    5. Build the dnn_semantic_segmentation_ex example program.
    6. Run:
       ./dnn_semantic_segmentation_ex /path/to/VOC2012-or-other-images

    An alternative to steps 2-4 above is to download a pre-trained network
    from here: http://dlib.net/files/semantic_segmentation_voc2012net_v2.dnn

    It would be a good idea to become familiar with dlib's DNN tooling before reading this
    example.  So you should read dnn_introduction_ex.cpp and dnn_introduction2_ex.cpp
    before reading this example program.
*/</font>

<font color='#0000FF'>#ifndef</font> DLIB_DNn_SEMANTIC_SEGMENTATION_EX_H_
<font color='#0000FF'>#define</font> DLIB_DNn_SEMANTIC_SEGMENTATION_EX_H_

<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>dlib<font color='#5555FF'>/</font>dnn.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='pascal_voc_2012.h.html'>pascal_voc_2012.h</a>"

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#009900'>// Introduce the building blocks used to define the segmentation network.
</font><font color='#009900'>// The network first does residual downsampling (similar to the dnn_imagenet_(train_)ex
</font><font color='#009900'>// example program), and then residual upsampling. In addition, U-Net style skip
</font><font color='#009900'>// connections are used, so that not every simple detail needs to reprented on the low
</font><font color='#009900'>// levels. (See Ronneberger et al. (2015), U-Net: Convolutional Networks for Biomedical
</font><font color='#009900'>// Image Segmentation, https://arxiv.org/pdf/1505.04597.pdf)
</font>
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font><font color='#5555FF'>&gt;</font> <font color='#0000FF'>class</font> <b><a name='BN'></a>BN</b>, <font color='#0000FF'><u>int</u></font> stride, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>using</font> block <font color='#5555FF'>=</font> BN<font color='#5555FF'>&lt;</font>dlib::con<font color='#5555FF'>&lt;</font>N,<font color='#979000'>3</font>,<font color='#979000'>3</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,dlib::relu<font color='#5555FF'>&lt;</font>BN<font color='#5555FF'>&lt;</font>dlib::con<font color='#5555FF'>&lt;</font>N,<font color='#979000'>3</font>,<font color='#979000'>3</font>,stride,stride,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;

<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font><font color='#5555FF'>&gt;</font> <font color='#0000FF'>class</font> <b><a name='BN'></a>BN</b>, <font color='#0000FF'><u>int</u></font> stride, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>using</font> blockt <font color='#5555FF'>=</font> BN<font color='#5555FF'>&lt;</font>dlib::cont<font color='#5555FF'>&lt;</font>N,<font color='#979000'>3</font>,<font color='#979000'>3</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,dlib::relu<font color='#5555FF'>&lt;</font>BN<font color='#5555FF'>&lt;</font>dlib::cont<font color='#5555FF'>&lt;</font>N,<font color='#979000'>3</font>,<font color='#979000'>3</font>,stride,stride,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;

<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'><u>int</u></font>,<font color='#0000FF'>template</font><font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font><font color='#5555FF'>&gt;</font><font color='#0000FF'>class</font>,<font color='#0000FF'><u>int</u></font>,<font color='#0000FF'>typename</font><font color='#5555FF'>&gt;</font> <font color='#0000FF'>class</font> <b><a name='block'></a>block</b>, <font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>template</font><font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font><font color='#5555FF'>&gt;</font><font color='#0000FF'>class</font> <b><a name='BN'></a>BN</b>, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>using</font> residual <font color='#5555FF'>=</font> dlib::add_prev1<font color='#5555FF'>&lt;</font>block<font color='#5555FF'>&lt;</font>N,BN,<font color='#979000'>1</font>,dlib::tag1<font color='#5555FF'>&lt;</font>SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;

<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'><u>int</u></font>,<font color='#0000FF'>template</font><font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font><font color='#5555FF'>&gt;</font><font color='#0000FF'>class</font>,<font color='#0000FF'><u>int</u></font>,<font color='#0000FF'>typename</font><font color='#5555FF'>&gt;</font> <font color='#0000FF'>class</font> <b><a name='block'></a>block</b>, <font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>template</font><font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font><font color='#5555FF'>&gt;</font><font color='#0000FF'>class</font> <b><a name='BN'></a>BN</b>, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>using</font> residual_down <font color='#5555FF'>=</font> dlib::add_prev2<font color='#5555FF'>&lt;</font>dlib::avg_pool<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,dlib::skip1<font color='#5555FF'>&lt;</font>dlib::tag2<font color='#5555FF'>&lt;</font>block<font color='#5555FF'>&lt;</font>N,BN,<font color='#979000'>2</font>,dlib::tag1<font color='#5555FF'>&lt;</font>SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;

<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'><u>int</u></font>,<font color='#0000FF'>template</font><font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font><font color='#5555FF'>&gt;</font><font color='#0000FF'>class</font>,<font color='#0000FF'><u>int</u></font>,<font color='#0000FF'>typename</font><font color='#5555FF'>&gt;</font> <font color='#0000FF'>class</font> <b><a name='block'></a>block</b>, <font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>template</font><font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font><font color='#5555FF'>&gt;</font><font color='#0000FF'>class</font> <b><a name='BN'></a>BN</b>, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>using</font> residual_up <font color='#5555FF'>=</font> dlib::add_prev2<font color='#5555FF'>&lt;</font>dlib::cont<font color='#5555FF'>&lt;</font>N,<font color='#979000'>2</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,dlib::skip1<font color='#5555FF'>&lt;</font>dlib::tag2<font color='#5555FF'>&lt;</font>blockt<font color='#5555FF'>&lt;</font>N,BN,<font color='#979000'>2</font>,dlib::tag1<font color='#5555FF'>&lt;</font>SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;

<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> res       <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'>&lt;</font>residual<font color='#5555FF'>&lt;</font>block,N,dlib::bn_con,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> ares      <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'>&lt;</font>residual<font color='#5555FF'>&lt;</font>block,N,dlib::affine,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> res_down  <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'>&lt;</font>residual_down<font color='#5555FF'>&lt;</font>block,N,dlib::bn_con,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> ares_down <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'>&lt;</font>residual_down<font color='#5555FF'>&lt;</font>block,N,dlib::affine,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> res_up    <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'>&lt;</font>residual_up<font color='#5555FF'>&lt;</font>block,N,dlib::bn_con,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'><u>int</u></font> N, <font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> ares_up   <font color='#5555FF'>=</font> dlib::relu<font color='#5555FF'>&lt;</font>residual_up<font color='#5555FF'>&lt;</font>block,N,dlib::affine,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> res64 <font color='#5555FF'>=</font> res<font color='#5555FF'>&lt;</font><font color='#979000'>64</font>,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> res128 <font color='#5555FF'>=</font> res<font color='#5555FF'>&lt;</font><font color='#979000'>128</font>,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> res256 <font color='#5555FF'>=</font> res<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> res512 <font color='#5555FF'>=</font> res<font color='#5555FF'>&lt;</font><font color='#979000'>512</font>,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> ares64 <font color='#5555FF'>=</font> ares<font color='#5555FF'>&lt;</font><font color='#979000'>64</font>,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> ares128 <font color='#5555FF'>=</font> ares<font color='#5555FF'>&lt;</font><font color='#979000'>128</font>,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> ares256 <font color='#5555FF'>=</font> ares<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> ares512 <font color='#5555FF'>=</font> ares<font color='#5555FF'>&lt;</font><font color='#979000'>512</font>,SUBNET<font color='#5555FF'>&gt;</font>;

<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> level1 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,res64,res<font color='#5555FF'>&lt;</font><font color='#979000'>64</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> level2 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,res128,res_down<font color='#5555FF'>&lt;</font><font color='#979000'>128</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> level3 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,res256,res_down<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> level4 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,res512,res_down<font color='#5555FF'>&lt;</font><font color='#979000'>512</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;

<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> alevel1 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,ares64,ares<font color='#5555FF'>&lt;</font><font color='#979000'>64</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> alevel2 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,ares128,ares_down<font color='#5555FF'>&lt;</font><font color='#979000'>128</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> alevel3 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,ares256,ares_down<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> alevel4 <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,ares512,ares_down<font color='#5555FF'>&lt;</font><font color='#979000'>512</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;

<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> level1t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,res64,res_up<font color='#5555FF'>&lt;</font><font color='#979000'>64</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> level2t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,res128,res_up<font color='#5555FF'>&lt;</font><font color='#979000'>128</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> level3t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,res256,res_up<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> level4t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,res512,res_up<font color='#5555FF'>&lt;</font><font color='#979000'>512</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;

<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> alevel1t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,ares64,ares_up<font color='#5555FF'>&lt;</font><font color='#979000'>64</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> alevel2t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,ares128,ares_up<font color='#5555FF'>&lt;</font><font color='#979000'>128</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> alevel3t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,ares256,ares_up<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> alevel4t <font color='#5555FF'>=</font> dlib::repeat<font color='#5555FF'>&lt;</font><font color='#979000'>2</font>,ares512,ares_up<font color='#5555FF'>&lt;</font><font color='#979000'>512</font>,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
    <font color='#0000FF'>template</font><font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font><font color='#5555FF'>&gt;</font> <font color='#0000FF'>class</font> <b><a name='TAGGED'></a>TAGGED</b>,
    <font color='#0000FF'>template</font><font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font><font color='#5555FF'>&gt;</font> <font color='#0000FF'>class</font> <b><a name='PREV_RESIZED'></a>PREV_RESIZED</b>,
    <font color='#0000FF'>typename</font> SUBNET
<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>using</font> resize_and_concat <font color='#5555FF'>=</font> dlib::add_layer<font color='#5555FF'>&lt;</font>
                          dlib::concat_<font color='#5555FF'>&lt;</font>TAGGED,PREV_RESIZED<font color='#5555FF'>&gt;</font>,
                          PREV_RESIZED<font color='#5555FF'>&lt;</font>dlib::resize_prev_to_tagged<font color='#5555FF'>&lt;</font>TAGGED,SUBNET<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;

<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> utag1 <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'>&lt;</font><font color='#979000'>2100</font><font color='#5555FF'>+</font><font color='#979000'>1</font>,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> utag2 <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'>&lt;</font><font color='#979000'>2100</font><font color='#5555FF'>+</font><font color='#979000'>2</font>,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> utag3 <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'>&lt;</font><font color='#979000'>2100</font><font color='#5555FF'>+</font><font color='#979000'>3</font>,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> utag4 <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'>&lt;</font><font color='#979000'>2100</font><font color='#5555FF'>+</font><font color='#979000'>4</font>,SUBNET<font color='#5555FF'>&gt;</font>;

<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> utag1_ <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'>&lt;</font><font color='#979000'>2110</font><font color='#5555FF'>+</font><font color='#979000'>1</font>,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> utag2_ <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'>&lt;</font><font color='#979000'>2110</font><font color='#5555FF'>+</font><font color='#979000'>2</font>,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> utag3_ <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'>&lt;</font><font color='#979000'>2110</font><font color='#5555FF'>+</font><font color='#979000'>3</font>,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> utag4_ <font color='#5555FF'>=</font> dlib::add_tag_layer<font color='#5555FF'>&lt;</font><font color='#979000'>2110</font><font color='#5555FF'>+</font><font color='#979000'>4</font>,SUBNET<font color='#5555FF'>&gt;</font>;

<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> concat_utag1 <font color='#5555FF'>=</font> resize_and_concat<font color='#5555FF'>&lt;</font>utag1,utag1_,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> concat_utag2 <font color='#5555FF'>=</font> resize_and_concat<font color='#5555FF'>&lt;</font>utag2,utag2_,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> concat_utag3 <font color='#5555FF'>=</font> resize_and_concat<font color='#5555FF'>&lt;</font>utag3,utag3_,SUBNET<font color='#5555FF'>&gt;</font>;
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SUBNET<font color='#5555FF'>&gt;</font> <font color='#0000FF'>using</font> concat_utag4 <font color='#5555FF'>=</font> resize_and_concat<font color='#5555FF'>&lt;</font>utag4,utag4_,SUBNET<font color='#5555FF'>&gt;</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>static</font> <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> semantic_segmentation_net_filename <font color='#5555FF'>=</font> "<font color='#CC0000'>semantic_segmentation_voc2012net_v2.dnn</font>";

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#009900'>// training network type
</font><font color='#0000FF'>using</font> bnet_type <font color='#5555FF'>=</font> dlib::loss_multiclass_log_per_pixel<font color='#5555FF'>&lt;</font>
                              dlib::cont<font color='#5555FF'>&lt;</font>class_count,<font color='#979000'>1</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,
                              dlib::relu<font color='#5555FF'>&lt;</font>dlib::bn_con<font color='#5555FF'>&lt;</font>dlib::cont<font color='#5555FF'>&lt;</font><font color='#979000'>64</font>,<font color='#979000'>7</font>,<font color='#979000'>7</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,
                              concat_utag1<font color='#5555FF'>&lt;</font>level1t<font color='#5555FF'>&lt;</font>
                              concat_utag2<font color='#5555FF'>&lt;</font>level2t<font color='#5555FF'>&lt;</font>
                              concat_utag3<font color='#5555FF'>&lt;</font>level3t<font color='#5555FF'>&lt;</font>
                              concat_utag4<font color='#5555FF'>&lt;</font>level4t<font color='#5555FF'>&lt;</font>
                              level4<font color='#5555FF'>&lt;</font>utag4<font color='#5555FF'>&lt;</font>
                              level3<font color='#5555FF'>&lt;</font>utag3<font color='#5555FF'>&lt;</font>
                              level2<font color='#5555FF'>&lt;</font>utag2<font color='#5555FF'>&lt;</font>
                              level1<font color='#5555FF'>&lt;</font>dlib::max_pool<font color='#5555FF'>&lt;</font><font color='#979000'>3</font>,<font color='#979000'>3</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,utag1<font color='#5555FF'>&lt;</font>
                              dlib::relu<font color='#5555FF'>&lt;</font>dlib::bn_con<font color='#5555FF'>&lt;</font>dlib::con<font color='#5555FF'>&lt;</font><font color='#979000'>64</font>,<font color='#979000'>7</font>,<font color='#979000'>7</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,
                              dlib::input<font color='#5555FF'>&lt;</font>dlib::matrix<font color='#5555FF'>&lt;</font>dlib::rgb_pixel<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>
                              <font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;

<font color='#009900'>// testing network type (replaced batch normalization with fixed affine transforms)
</font><font color='#0000FF'>using</font> anet_type <font color='#5555FF'>=</font> dlib::loss_multiclass_log_per_pixel<font color='#5555FF'>&lt;</font>
                              dlib::cont<font color='#5555FF'>&lt;</font>class_count,<font color='#979000'>1</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,<font color='#979000'>1</font>,
                              dlib::relu<font color='#5555FF'>&lt;</font>dlib::affine<font color='#5555FF'>&lt;</font>dlib::cont<font color='#5555FF'>&lt;</font><font color='#979000'>64</font>,<font color='#979000'>7</font>,<font color='#979000'>7</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,
                              concat_utag1<font color='#5555FF'>&lt;</font>alevel1t<font color='#5555FF'>&lt;</font>
                              concat_utag2<font color='#5555FF'>&lt;</font>alevel2t<font color='#5555FF'>&lt;</font>
                              concat_utag3<font color='#5555FF'>&lt;</font>alevel3t<font color='#5555FF'>&lt;</font>
                              concat_utag4<font color='#5555FF'>&lt;</font>alevel4t<font color='#5555FF'>&lt;</font>
                              alevel4<font color='#5555FF'>&lt;</font>utag4<font color='#5555FF'>&lt;</font>
                              alevel3<font color='#5555FF'>&lt;</font>utag3<font color='#5555FF'>&lt;</font>
                              alevel2<font color='#5555FF'>&lt;</font>utag2<font color='#5555FF'>&lt;</font>
                              alevel1<font color='#5555FF'>&lt;</font>dlib::max_pool<font color='#5555FF'>&lt;</font><font color='#979000'>3</font>,<font color='#979000'>3</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,utag1<font color='#5555FF'>&lt;</font>
                              dlib::relu<font color='#5555FF'>&lt;</font>dlib::affine<font color='#5555FF'>&lt;</font>dlib::con<font color='#5555FF'>&lt;</font><font color='#979000'>64</font>,<font color='#979000'>7</font>,<font color='#979000'>7</font>,<font color='#979000'>2</font>,<font color='#979000'>2</font>,
                              dlib::input<font color='#5555FF'>&lt;</font>dlib::matrix<font color='#5555FF'>&lt;</font>dlib::rgb_pixel<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>
                              <font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_DNn_SEMANTIC_SEGMENTATION_EX_H_
</font>
</pre></body></html>